{% extends "admin/base.html" %}

{% block admin_content %}
<div class="card">
    <div class="card-header py-3 d-flex justify-content-between align-items-center">
        <h6 class="m-0 font-weight-bold text-primary">系统配置</h6>
    </div>
    <div class="card-body">
        <form id="configForm">
            <div class="row">
                <div class="col-md-6">
                    <div class="mb-4">
                        <label for="questions_per_draw" class="form-label">
                            <i class="bi bi-question-circle me-1"></i>每次抽题数量
                        </label>
                        <div class="input-group">
                            <input type="number" class="form-control" id="questions_per_draw" name="questions_per_draw" 
                                   value="{{ configs.get('questions_per_draw', 1) }}" min="1" required>
                            <span class="input-group-text">题</span>
                        </div>
                        <div class="form-text text-muted">设置每次抽取的题目数量，最小为1</div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="mb-4">
                        <label for="retry_limit" class="form-label">
                            <i class="bi bi-arrow-repeat me-1"></i>最大重抽次数
                        </label>
                        <div class="input-group">
                            <input type="number" class="form-control" id="retry_limit" name="retry_limit" 
                                   value="{{ configs.get('retry_limit', 3) }}" min="0" required>
                            <span class="input-group-text">次</span>
                        </div>
                        <div class="form-text text-muted">设置每个用户最多可以重抽的次数，0表示不允许重抽</div>
                    </div>
                </div>
            </div>
            <div class="d-flex justify-content-end">
                <button type="button" id="saveConfig" class="btn btn-primary">
                    <i class="bi bi-save me-1"></i>保存配置
                </button>
            </div>
        </form>
    </div>
</div>

<!-- 成功提示模态框 -->
<div class="modal fade" id="successModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header border-0">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body text-center">
                <div class="mb-3">
                    <i class="bi bi-check-circle-fill text-success" style="font-size: 3rem;"></i>
                </div>
                <h5 class="modal-title mb-3">配置已更新</h5>
                <p class="text-muted">系统配置已成功更新，新的设置将立即生效。</p>
            </div>
            <div class="modal-footer border-0 justify-content-center">
                <button type="button" class="btn btn-primary" data-bs-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- 错误提示模态框 -->
<div class="modal fade" id="errorModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header border-0">
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body text-center">
                <div class="mb-3">
                    <i class="bi bi-x-circle-fill text-danger" style="font-size: 3rem;"></i>
                </div>
                <h5 class="modal-title mb-3">更新失败</h5>
                <p class="text-muted" id="errorMessage">更新配置时发生错误，请稍后重试。</p>
            </div>
            <div class="modal-footer border-0 justify-content-center">
                <button type="button" class="btn btn-primary" data-bs-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
    <script src="{{ url_for('static', filename='js/config.js') }}"></script>
{% endblock %} 